package com.easyapi.controller.execute;


import com.easyapi.common.Constants;
import com.easyapi.common.utils.BaseResponse;

import com.easyapi.service.execute.GenerateApiExecuteService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 生成 api--向导模式通用请求类
 */
@RestController
@RequestMapping(Constants.BASE_URL)
public class GenerateInterfaceBaseController {

    @Resource
    private GenerateApiExecuteService generateApiExecuteService;

    @PostMapping("basePost")
    public BaseResponse<Object> generateInterfacePostExecute(@RequestBody Map<String, String> params, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        try {
           return generateApiExecuteService.execute(requestURI, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("baseGet")
    public BaseResponse<Object> generateInterfaceGetExecute(@RequestParam Map<String,String> params,HttpServletRequest request){
        String requestURI = request.getRequestURI();
        try {
            return generateApiExecuteService.execute(requestURI, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
